<template>
    <!--选择车位的 弹框-->
    <el-dialog title="选择业主" append-to-body :visible.sync="visible" width="900px">
        <el-form ref="userFormRef" :model="form" inline label-width="100px">
            <el-form-item label="业主名称" prop="userName">
                <el-input v-model="form.userName" placeholder="请输入停车位编号" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <JTable v-loading="loading" :data="ownerUserList" height="400">
            <el-table-column label="名称" align="center" prop="userName" />
            <el-table-column label="性别" align="center" prop="sex">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
                </template>
            </el-table-column>
            <el-table-column label="年龄" align="center" prop="" />
            <el-table-column label="身份证" align="center" prop="idcard" width="155" />
            <el-table-column label="联系方式" align="center" prop="phonenumber"></el-table-column>
            <!-- <el-table-column label="创建员工" align="center" prop="status" /> -->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="primary" @click="handleSelect(scope.row)">选择</el-button>
                </template>
            </el-table-column>
        </JTable>
        <pagination v-show="total > 0" :total="total" :page.sync="form.currentPage" :limit.sync="form.pageSize" @pagination="getList" />
    </el-dialog>
</template>
<script>
import { listOwnerUser } from '@/api/owner/ownerUser';
export default {
    dicts: ['sys_user_sex'],
    props: {},
    data() {
        return {
            // 遮罩层
            loading: true,
            visible: false,
            total: 0,
            ownerUserList: [],
            form: {
                currentPage: 1,
                pageSize: 10,
                userName: '',
            },
        };
    },
    methods: {
        init() {
            this.visible = true;
            this.$nextTick(() => {
                this.$refs['userFormRef'].resetFields();
                this.getList();
            });
        },
        /** 查询业主信息列表 */
        getList() {
            this.loading = true;
            listOwnerUser(this.form).then(response => {
                this.loading = false;
                this.ownerUserList = response.data.list;
                this.total = response.data.pagination.total;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.form.currentPage = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('userFormRef');
            this.form.currentPage = 1;
            this.getList();
        },
        // 选择了一个 业主
        handleSelect(row) {
            this.visible = false;
            this.$emit('handleSelectUserInfo', row);
        },
    },
};
</script>
